package com.bw.goods.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @Author：尚志豪
 * @Package：com.bw.goods.config
 * @Project：ruoyiszh
 * @name：Feignlnterceptor
 * @Date：2024/12/20 15:59
 */
@Configuration
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        if ("post".equalsIgnoreCase(requestTemplate.method()) && requestTemplate.body() == null) {
            String query = requestTemplate.queryLine();
            requestTemplate.queries(new HashMap<>());
            if (query!=null && query.startsWith("?")) {
                requestTemplate.body(query.substring(1));
            }
            requestTemplate.header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        }
    }
}
